<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="./jquery.min.js"></script>
</head>

<body>
    <button id="btnGet">GET</button>
    <button id="btnPost">POST</button>
    <button id="btnJsonp">JSONP</button>

    <script>
        $(function() {
            // 1.测试get接口
            $('#btnGet').on('click', function() {
                $.ajax({
                    method: 'GET',
                    url: 'http://127.0.0.1/api/get',
                    data: {
                        name: 'zs',
                        age: 18
                    },
                    success: function(res) {
                        console.log(res);
                    }
                })
            });
            // 2.测试Post接口
            $('#btnPost').on('click', function() {
                $.ajax({
                    method: 'POST',
                    url: 'http://127.0.0.1/api/post',
                    data: {
                        bookname: '水浒传',
                        author: '施耐庵'
                    },
                    success: function(res) {
                        console.log(res);
                    }
                })
            });
            // 3.为 jsonp 按钮绑定点击事件处理函数
            $('#btnJsonp').on('click', function() {
                $.ajax({
                    type: 'GET',
                    url: 'http://127.0.0.1/api/jsonp',
                    dataType: 'jsonp',
                    success: function(res) {
                        console.log(res);
                    }
                })
            })


        })
    </script>

</body>


</html>